package com.enjoyor.soa.traffic.rest.efoms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.efoms.DeviceWranInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IDeviceWranInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Auth
@RestController
@RequestMapping({ "/wran" })
@Api("设备报警rest接口")
@CrossOrigin
public class DeviceWranInfoController {
	@Autowired
	private IDeviceWranInfoConsumeService deviceWranInfoConsumeService;

	@GetMapping(value = { "getDeviceWranInfoById" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("根据编号查询报警信息")
	@ApiImplicitParam(name = "devWranId", value = "报警编号", paramType = "query", required = true, dataType = "String")
	public ResultPojo getDeviceWranInfoById(
			@RequestParam(defaultValue = "", value = "devWranId", required = false) String devWranId,
			HttpServletRequest request) {
		return deviceWranInfoConsumeService.selectDeviceWranInfoById(devWranId);
	}
	
	@GetMapping(value = { "getDeviceWranInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("查询报警列表信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "devWranId", value = "报警编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devCategoryCode", value = "设备种类编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devName", value = "设备名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "key", value = "关键字（设备编号或设备名称）", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranTypeCode", value = "报警类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranLevelCode", value = "报警等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranContent", value = "报警内容", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "isRecover", value = "是否恢复正常", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranStartTime", value = "报警开始时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranEndTime", value = "报警结束时间", paramType = "query", dataType = "String")})
	public ResultPojo getDeviceWranInfoList(
			@RequestParam(defaultValue = "", value = "devWranId", required = false) String devWranId,
			@RequestParam(defaultValue = "", value = "devCategoryCode", required = false) String devCategoryCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "devId", required = false) String devId,
			@RequestParam(defaultValue = "", value = "devName", required = false) String devName,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			@RequestParam(defaultValue = "", value = "wranTypeCode", required = false) String wranTypeCode,
			@RequestParam(defaultValue = "", value = "wranLevelCode", required = false) String wranLevelCode,
			@RequestParam(defaultValue = "", value = "wranContent", required = false) String wranContent,
			@RequestParam(defaultValue = "", value = "isRecover", required = false) String isRecover,
			@RequestParam(defaultValue = "", value = "wranStartTime", required = false) String wranStartTime,
			@RequestParam(defaultValue = "", value = "wranEndTime", required = false) String wranEndTime,
			HttpServletRequest request) {
		return deviceWranInfoConsumeService.selectDeviceWranInfoList(devWranId, devCategoryCode, devTypeCode, devId,
				devName, key, wranTypeCode, wranLevelCode, wranContent, isRecover, wranStartTime, wranEndTime);
	}
	
	@GetMapping(value = { "getDeviceWranReal" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("查询最新实时报警信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "devCategoryCode", value = "设备种类编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "isRecover", value = "是否恢复正常", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranStartTime", value = "报警开始时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranEndTime", value = "报警结束时间", paramType = "query", dataType = "String")})
	public ResultPojo getDeviceWranReal(
			@RequestParam(defaultValue = "", value = "devCategoryCode", required = false) String devCategoryCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "isRecover", required = false) String isRecover,
			@RequestParam(defaultValue = "", value = "wranStartTime", required = false) String wranStartTime,
			@RequestParam(defaultValue = "", value = "wranEndTime", required = false) String wranEndTime,
			HttpServletRequest request) {
		return deviceWranInfoConsumeService.selectDeviceWranReal(devCategoryCode, devTypeCode,
				isRecover, wranStartTime, wranEndTime);
	}

	@SuppressWarnings({ "rawtypes" })
	@GetMapping(value = { "/getDeviceWranInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("查询报警分页信息")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "devWranId", value = "报警编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devCategoryCode", value = "设备种类编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devName", value = "设备名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "key", value = "关键字（设备编号或设备名称）", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranTypeCode", value = "报警类型编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranLevelCode", value = "报警等级编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranContent", value = "报警内容", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "isRecover", value = "是否恢复正常", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranStartTime", value = "报警开始时间", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "wranEndTime", value = "报警结束时间", paramType = "query", dataType = "String")})
	public ResultPojo getDeviceWranInfoPage(
			@RequestParam(defaultValue = "", value = "devWranId", required = false) String devWranId,
			@RequestParam(defaultValue = "", value = "devCategoryCode", required = false) String devCategoryCode,
			@RequestParam(defaultValue = "", value = "devTypeCode", required = false) String devTypeCode,
			@RequestParam(defaultValue = "", value = "devId", required = false) String devId,
			@RequestParam(defaultValue = "", value = "devName", required = false) String devName,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			@RequestParam(defaultValue = "", value = "wranTypeCode", required = false) String wranTypeCode,
			@RequestParam(defaultValue = "", value = "wranLevelCode", required = false) String wranLevelCode,
			@RequestParam(defaultValue = "", value = "wranContent", required = false) String wranContent,
			@RequestParam(defaultValue = "", value = "isRecover", required = false) String isRecover,
			@RequestParam(defaultValue = "", value = "wranStartTime", required = false) String wranStartTime,
			@RequestParam(defaultValue = "", value = "wranEndTime", required = false) String wranEndTime,
			Page page, HttpServletRequest request) {
		return deviceWranInfoConsumeService.selectDeviceWranInfoPage(page, devWranId, devCategoryCode, devTypeCode,
				devId, devName, key, wranTypeCode, wranLevelCode, wranContent, isRecover, wranStartTime, wranEndTime);
	}

	@PostMapping(value = { "/insertDeviceWranInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("新增报警信息")
	public ResultPojo insertDeviceWranInfo(
    		@RequestBody DeviceWranInfoDto deviceWranInfoDto, HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
		return deviceWranInfoConsumeService.insertDeviceWranInfo(deviceWranInfoDto, username);
	}
	
	@PutMapping(value = { "/updateDeviceWranInfo" }, consumes = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("更新报警信息")
    public ResultPojo updateDeviceWranInfo(
    		@RequestBody DeviceWranInfoDto deviceWranInfoDto, HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
        return deviceWranInfoConsumeService.updateDeviceWranInfo(deviceWranInfoDto, username);
    }
	
	@DeleteMapping(value = { "/deleteDeviceWranInfo" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除报警信息")
    @ApiImplicitParam(name = "devWranId", value = "报警编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo deleteDeviceWranInfo(
    		@RequestParam(defaultValue = "", value = "devWranId", required = true) String devWranId,
    		HttpServletRequest request) {
		String username = ((UserDto) request.getAttribute("currentUser")).getPersonName();
        return deviceWranInfoConsumeService.deleteDeviceWranInfo(devWranId, username);
    }
	
}
